<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserAgentExtendTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_agent_extend', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('代理用户id');
            $table->string('audit_status')->default('wait_audit')
                ->comment('审核状态 wait_audit：待审核；approved：已审核；rejection：已拒绝');
            $table->unsignedInteger('agent_level')->comment('代理级别 1，2，3');
            $table->unsignedInteger('parent_user_id')->nullable()->comment('上级代理用户ID');
            $table->integer('proration')->comment('分红比例 单位：%');
            $table->json('prorations')->comment('各级代理分红比例 {v1:xxx，v2:xxx，v3:xxx} 单位: %');
            $table->unsignedInteger('operation_user_id')->comment('操作人');
            $table->timestamps();

            $table->index('user_id');
            $table->index('parent_user_id');

            $table->foreign('user_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_agent_extend');
    }
}
